﻿#include "fcgiplus.hpp"
#include "eiendb.hpp"
#include "eiennet.hpp"
#include "eiengd.hpp"
#include "eienexpr.hpp"
#include "eientpl.hpp"
#include "fcgiserv.hpp"
#include <iostream>
using namespace std;
using namespace winux;
using namespace eiendb;
using namespace eiennet;
using namespace eiengd;
using namespace eienexpr;
using namespace eientpl;
using namespace fcgi;


class TemplateLangExpMath
{
public:
    static void Init() {
        __initExprFuncs();
    }
    static void Dispose() {
    }

    private:
    // random(n1,n2)
    static bool __FuncRandom( std::vector<eienexpr::Expression *> & params, winux::SimplePointer<eienexpr::ExprOperand> * outRetValue, void * data )
    {
        outRetValue->attachNew(NULL);
        if ( params.size() == 2 )
        {
            int n1 = params[0]->val();
            int n2 = params[1]->val();
            outRetValue->attachNew( new eienexpr::ExprLiteral( winux::Random(n1,n2) ) );
            return true;
        }
        else
        {
            throw eienexpr::ExprError( eienexpr::ExprError::eeFuncParamCountError, "`random()` parameters wrong!" );
        }
        return false;
    }
    static void __initExprFuncs()
    {
        // random(n1,n2)
        eienexpr::ExprFunc::SetFunc( "random", TemplateLangExpMath::__FuncRandom );
    }
};



int main( int argc, char const * argv[] )
{
#if defined(__GNUC__) && !defined(WIN32) // on linux
    SetLocale::Set("zh_CN.UTF-8");
#endif
    winux::SetLocale __loc__;
    try
    {
// `include/tplexp_math.inc.ecp` embed code is empty!



Template tpl( "template" );
tpl.assign("word", "yes");


TemplateLangExpMath::Init();
cout << tpl.output("test","");
TemplateLangExpMath::Dispose();

    }
    catch ( std::exception const & e )
    {
        cout << e.what() << endl;
    }
    catch (...)
    {
        cout << "Unknown error" << endl;
    }
    return 0;
}

